package com.example.mybatisplus.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.mapper.UserMapper;
import com.example.mybatisplus.pojo.User;
import com.example.mybatisplus.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public IPage<User> find(Integer maxAge, Integer minAge, String address, Integer currentPage) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        if (maxAge != null) {
            wrapper.ge("age", maxAge);
        }
        if (minAge != null) {
            wrapper.le("age", minAge);
        }
        if (address != null) {
            wrapper.like("address", address);
        }
        Page<User> userPage = new Page<>(currentPage, 10);
        return userMapper.selectPage(userPage, wrapper);
    }
}